

package vinterprojekt;

/**
 * 
 * @author jacob
 */

import vinterprojekt.gui.AppFrame;
import vinterprojekt.controller.DBController;
import java.awt.event.WindowAdapter;


public class Main
{
    public static void main(String[] args)
    {
        String DBFile = "bookdb.sqlite";
        DBController.configure(DBFile);

        setLookAndFeel();
        startApp();
    }

    private static void setLookAndFeel()
    {
        // sæt platforms look-and-feel, så programmet ligner et "native" Windows ell. linux program
        try
        {
            javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());

        }

        catch (Exception e)
        {
            vinterprojekt.util.ErrorHandler.error(e, true);
        }
    }

    private static void startApp()
    {
        Runnable task = new Runnable()
        {
            public void run()
            {

                AppFrame frame = new AppFrame();
                frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);

                WindowAdapter ad = new WindowAdapter()
                {
                    @Override public void windowClosing(java.awt.event.WindowEvent we)
                    {
                        //svarer til flush() som på en OutputStream, uden close() kaldet bliver data ikke
                        // gemt fra gang til gang
                        DBController.getInstance().close();
                    }

                };

                frame.addWindowListener(ad);
                frame.setVisible(true);
            }
        };

        javax.swing.SwingUtilities.invokeLater(task);
    }

}
